package com.phantasy.modules.scene
{
	import com.phantasy.common.GlobalObjectManager;
	import com.phantasy.managers.LayerManager;
	import com.phantasy.modules.BaseModule;
	import com.phantasy.modules.ModuleCommand;
	import com.phantasy.modules.scene.cases.MapCase;
	import com.phantasy.scene.GameScene;
	
	public class SceneModule extends BaseModule
	{
		private static var instance:SceneModule;
		private var _inited:Boolean;
		public var view:GameScene;
		public function SceneModule()
		{
			init();
			super();
		}
		
		public static function getInstance():SceneModule
		{
			if(instance==null){
				instance = new SceneModule();
			}
			return SceneModule.instance;
		}
		
		private function init():void
		{
			if(_inited==false)
			{
				this.view = GameScene.getInstance();
				
				_inited=true;
			}
		}
		
		/**
		 *获取是否初始化成功 
		 * @return 
		 * 
		 */		
		public function get isInited():Boolean
		{
			return this._inited;
		}
		
		override protected function initListeners():void
		{
			addMessageListener(ModuleCommand.START_UP_SCENE, this.onStartUpScene);
		}
		
		private function onStartUpScene():void
		{
			this.init();
			//将gameScene显示对象放到场景层中
			if(this.view.parent==null){
				LayerManager.sceneLayer.addChild(this.view);
			}
			//如果是首次进入地图
			if(MapCase.getInstance().isFirstEnterMap){
				MapCase.getInstance().toEnter(GlobalObjectManager.getInstance().user.pos.map_id)
			}
		}
	}
}